CFLAGS= -c -Wall

CFLAGS_MAIN= -g -lz -lsqlite3 -pthread -lcrypto -D_M_IX86 -o server
CFLAGS_MAIN_PRIVADD= -Wall -g -lz -lsqlite3 -pthread -o privilegeadd
CFLAGS_MAIN_PRIVDEL= -Wall -g -lz -lsqlite3 -pthread -o privilegedel
CFLAGS_MAIN_SECTADD= -Wall -g -lz -lsqlite3 -pthread -o sectoradd
CFLAGS_MAIN_USERADD= -Wall -g -lz -lsqlite3 -pthread -lcrypto -o useradd

SOURCE_SERVER = server.c
SOURCE_PRIVILEGE = privilege.c
SOURCE_DB = db.c
SOURCE_DOCUMENT_ACCESS = documentaccess.c
SOURCE_PRIVILEGEADD = privilegeadd.c
SOURCE_PRIVILEGEDEL = privilegedel.c
SOURCE_SECTORADD = sectoradd.c
SOURCE_USERADD = useradd.c

DEPENDS_SERVER = $(SOURCE_SERVER) $(OBJECTS_SERVER)
DEPENDS_PRIVILEGE = db.h structures.h
DEPENDS_DB =  structures.h ../sha2/sha2.h
DEPENDS_DOCUMENT_ACCESS = db.h structures.h
DEPENDS_PRIVILEGEADD = $(SOURCE_PRIVILEGEADD) $(OBJECTS_PRIVILEGEADD)
DEPENDS_PRIVILEGEDEL = $(SOURCE_PRIVILEGEDEL) $(OBJECTS_PRIVILEGEDEL)
DEPENDS_SECTORADD = $(SOURCE_SECTORADD) $(OBJECTS_SECTORADD)
DEPENDS_USERADD = $(SOURCE_USERADD) $(OBJECTS_USERADD)

OBJECTS_SERVER = ../rsa/myRsa.o ../sha2/sha2.o privilege.o documentaccess.o db.o ../twofish/myTwofish2.o ../twofish/zlib_use.o ../twofish/twofish2.o ../log/sec_logger.o ../log/logger.o
OBJECTS_PRIVILEGEADD = db.o ../sha2/sha2.o
OBJECTS_PRIVILEGEDEL = db.o ../sha2/sha2.o
OBJECTS_SECTORADD = db.o ../sha2/sha2.o
OBJECTS_USERADD = db.o ../sha2/sha2.o ../rsa/myRsa.o ../twofish/myTwofish2.o ../twofish/zlib_use.o ../twofish/twofish2.o ../common/publicReader.o

.PHONY: clean

all: clean privilege db documentaccess privilegeadd privilegedel sectoradd useradd server

clean:
	-rm -rf *.o *.*~ *.xml server privilegeadd privilegedel sectoradd useradd

privilege: $(DEPENDS_PRIVILEGE)
	cc $(CFLAGS) $(SOURCE_PRIVILEGE)

db: $(DEPENDS_DB)
	cc $(CFLAGS) $(SOURCE_DB)

documentaccess: $(DEPENDS_DOCUMENT_ACCESS)
	cc $(CFLAGS) $(SOURCE_DOCUMENT_ACCESS)

server: $(DEPENDS_SERVER)
	cc $(SOURCE_SERVER) $(OBJECTS_SERVER) $(CFLAGS_MAIN)
	
privilegeadd: $(DEPENDS_PRIVILEGEADD)
	cc $(SOURCE_PRIVILEGEADD) $(OBJECTS_PRIVILEGEADD)  $(CFLAGS_MAIN_PRIVADD)

privilegedel: $(DEPENDS_PRIVILEGEDEL)
	cc $(SOURCE_PRIVILEGEDEL) $(OBJECTS_PRIVILEGEDEL)  $(CFLAGS_MAIN_PRIVDEL)

sectoradd: $(DEPENDS_SECTORADD)
	cc $(SOURCE_SECTORADD) $(OBJECTS_SECTORADD) $(CFLAGS_MAIN_SECTADD)

useradd: $(DEPENDS_USERADD)
	cc $(SOURCE_USERADD) $(OBJECTS_USERADD)  $(CFLAGS_MAIN_USERADD)

